#include <iostream>
#include"context.h"
#include<thread>
#include<chrono>
using namespace std;

int main()
{
    TrafficLights tl;

    enum class TLState {Red, Green, Yellow};

    TLState state = TLState::Red;  // 初始状态为红灯
    int i = 0;  // 总次数
    int seconds;  // 秒数

    while (true) {
        // 表示一个完整的状态流（红灯->绿灯->黄灯）已经完成
        if (i % 3 == 0)
            std::cout << "**********" << "Session " << ((i+1)/3)+1 << "**********" << std::endl;

        // 根据当前状态来设置持续时间，红灯（6秒）、绿灯（4秒）、黄灯（2秒）
        if (state == TLState::Red) {
            seconds = 6;
            state = TLState::Green;
        } else if (state == TLState::Green) {
            seconds = 4;
            state = TLState::Yellow;
        } else if (state == TLState::Yellow) {
            seconds = 2;
            state = TLState::Red;
        }

        // 休眠    
        std::this_thread::sleep_for(std::chrono::seconds(seconds));
        tl.Request();
        i++;
    }

    return 0;
}
